<template>
  <div class="rank-container">
    <div class="top">
      <img src="../assets/back.png" alt="" @click="$router.go(-1)">
      <span>排行榜</span>
    </div>
    <div class="content" v-for="item in state.toplist" :key="item.id" @click="$router.push(`/listview?id=${item.id}`)">
      <div class="left">
        <img :src="item.coverImgUrl" alt="">
        <span class="count">{{ parseInt(item.playCount/10000) }}万</span>
      </div>
      <div class="right">
        <div class="name">{{item.name}}</div>
        <div class="update">{{item.updateFrequency}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCurrentInstance, reactive } from 'vue'
// import { lazyload } from '../utils/lazyload'
/**
 * TODO: 增加图片懒加载,增减歌单右侧歌单前三名展示
 */

export default {
  async setup() {
    const { proxy } = getCurrentInstance()
    // 定义数据
    const state = reactive({ toplist: [] })

    proxy.$http.get('/toplist').then(res => {
      if (res.code === 200) {
        state.toplist = res.list
        // console.log(res.list)
      }
    })

    await proxy.$http.get('/toplist')

    return {
      state
    }
  }
}

// function lazyload() {
//   const datas = document.querySelectorAll('.content')
//   // 视口的高度
//   const viewHeight = document.documentElement.clientHeight
//   // 滚动条高度
//   const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop
//   console.log('视口高度：', viewHeight)
//   console.log('滚动条高度', scrollHeight)
//   console.log(datas[5].offsetTop)
// }

// window.addEventListener('scroll', lazyload)
</script>

<style lang="less" scoped>
.rank-container {
  width: 7.5rem;
  font-size: 0.4rem;
  .top {
    display: flex;
    padding: 0.2rem;
    img {
      height: 0.7rem;
      width: 0.7rem;
    }
    span {
      flex: 1;
      text-align: center;
    }
  }
  .content {
    height: 3rem;
    display: flex;
    margin: 0.2rem;
    border-radius: 0.2rem;
    .left {
      position: relative;
      img {
        height: 3rem;
        width: 3rem;
        border-radius: 0.2rem;
      }
      .count {
        position: absolute;
        bottom: 0.1rem;
        right: 0.1rem;
        font-size: 0.3rem;
        color: #ccc;
      }
      .count::before {
        content: '☊ ';
      }
    }
    .right {
      margin-left: 0.5rem;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .name {
        font-size: 0.4rem;
        font-weight: 600;
      }
      .update {
        color: #ccc;
      }
    }
  }
}
</style>